// 设置cookie
export function setCookie (name, value, time) {
    let date = new Date()
    date.setTime(date.getTime() + time)
    document.cookie = `${name}=${value};path=/;expires=${date.toUTCString()}`
}

// 获取cookie
export function getCookie (name) {
    let result = null
    if (document.cookie.length > 0) {
        let arr = document.cookie.split(';')
        arr.forEach(value => {
            let arr2 = value.split('=')
            if (arr2[0].trim() === name) {
                result = arr2[1]
            }
        })
    }
    return result
}

// 移除cookie
export function removeCookie (name) {
    document.cookie = `${name}=;path=/;expires=${new Date(-1)}`
}

// 清空cookie
export function clearCookie () {
    if (document.cookie.length > 0) {
        let arr = document.cookie.split(';')
        arr.forEach(value => {
            let arr2 = value.split('=')
            document.cookie = `${arr2[0]}=;path=/;expires=${new Date(-1)}`
        })
    }
}
